//
//  TextFieldUtil.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/3/28.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "TextFieldUtil.h"
#import "Masonry.h"
#import "UILabel+XExtension.h"

@implementation TextFieldUtil

#pragma mark - Public
+ (void)loadTextFieldWithTitle:(NSString *)title
                      withUnit:(NSString *)unit
                 withTextField:(UITextField *)textField
                   andBackView:(UIView *)backView{
    UILabel *titleLabel = [UILabel new];
    titleLabel.font = [UIFont systemFontOfSize:14];
    titleLabel.text = title;
    titleLabel.tag = 1;
    titleLabel.textColor = [UIColor colorWithRed:80/255.0 green:80/255.0 blue:80/255.0 alpha:1.0];
    UILabel *unitLabel = [UILabel new];
    unitLabel.text = unit;
    unitLabel.tag = 2;
    unitLabel.font = [UIFont systemFontOfSize:14];
    unitLabel.textColor = [UIColor colorWithRed:80/255.0 green:80/255.0 blue:80/255.0 alpha:1.0];
    
    [backView addSubview:titleLabel];
    [backView addSubview:textField];
    [backView addSubview:unitLabel];
    
    CGRect tmpRect = [titleLabel calculateBounds];
    CGRect tmpRect2 = [unitLabel calculateBounds];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(backView);
        make.width.mas_equalTo(tmpRect.size.width);
        
    }];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right);
        make.top.bottom.equalTo(backView);
    }];
    [unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(textField.mas_right).offset(5);
        make.top.bottom.equalTo(backView);
        make.right.equalTo(backView);
        make.width.equalTo(tmpRect2.size.width);
    }];
}

@end
